/**
 * 新开历史医嘱
 */
function lishiyizhu()
{
	laytplUrl(myurl + "/module/history.html", [],
			function(data, html) {
				$("#history_table").html(html);
				layer.open({
					  type: 1,
					  title:'历史医嘱',
					  area: ['1300px', '700px'], //宽高
					  content: html,
					  success: function()
					{
						  if(!$("#history_table").html())
							{
								//加载jqgrid
								showHistroyAdvice();
								$("#history_cancle").on("click",function(){
									layer.close(index);
								})
							}
					}
					});
	}
	);
}
function showHistroyAdvice(){
	 var arr = [];//检验
	 $.ajax({
		 url : rootUrl + "/doctoradvice/patientsuccessivedoctoradvicerecord",
		 type : "post",
		 dataType : 'json',
		 async : false,
		 data :
			{
				"EmpID": bce01,
				"lVAA01": vaa01,
			    "lVAF04" : 1,
			    "lCheck" : 0,
			    "productid" : 100,
			    "programid" : 105002,
			    "paramno" : 233,
			    "currPage" : 1,
			    "pageSize" : 30
			},
			success : function(data){
				debugger;
				var temp = data.list;
				for(var i=0;i<temp.length;i++){
					var dataObj=temp[i];
					dataObj.data_info = JSON.stringify(temp[i]);
					arr.push(dataObj);
				}
				HistroyAdviceInit(arr);
			}
		
	 })
}
function HistroyAdviceInit(arr)
{
	layer.msg('加载中....', {icon: 16,skin: 'layui-layer-msg16',shade: [0.1, '#393D49'],time:1*400}); 
	jQuery('#history_table').GridUnload();
	jQuery("#history_table").jqGrid(
	{
	datatype: 'local', 
	data:arr,
	colModel :
	[
	{
	label : " ",
	name : 'copy'
	},
	{
	label : "医嘱内容",
	name : 'vaf22n'
	},
	{
	label : "皮试",
	name : 'vaf25'
	},
	{
	label : "用法",
	name : 'fusage'
	},
	{
	label : "总量",
	name : 'vaf21'
	},
	{
	label : "单位",
	name : 'fgross'
	},
	{
	label : "医生嘱托",
	name : 'vaf23'
	},
	{
	label : "执行科室",
	name : 'nbck03'
	},
	{
	label : "附加执行",
	name : 'bck03c'
	},
	{
	label : "执行性质",
	name : 'vaf58'
	},
	{
	label : "计价性质",
	name : 'vaf31'
	},
	{
	label : "用药目的",
	name : 'biw02'
	},
	{
	label : "医嘱备注",
	name : 'vaf55'
	}, 
	{
	label : "开嘱医生",
	name : 'bce03g'
	},
	{
		name : 'bby01',
		hidden:true
	},
	{
		name : 'bda01',
		hidden:true
	},
	{
		name : 'vaf01',
		hidden:true
	},
	{
		name : 'vaf22',
		hidden:true
	},
	{
		name : 'bbx01',
		hidden:true
	},
	{
		name : 'vaf36_',
		hidden:true
	},
	{
		name : 'cbm01',
		hidden:true
	},
	{
		name : 'data_info',
		hidden:true
	}
	],
	sortname : 'id',
	viewrecords : true,
	multiselect : true,
	height : 'auto',
	width : '100%',
//	autowidth : true,
	forceFit:true,
    shrinkToFit:true,
	rownumbers : true,
	grouping:true,
   	groupingView : 
   	{
   		groupField : ['vaf36_','cbm01'],
   		groupColumnShow : [false,false],
   		groupText : ['<b>{0}</b>','<b>{0}</b>']
   	},
	gridComplete : function()
	{
		var ids = jQuery("#history_table").jqGrid('getDataIDs');
		for (var i = 0; i < ids.length; i++)
		{
			var cl = ids[i];
			var copyInput = "<input style='height:22px;width:50px;'class='btn btn-white' type='button' value='复制' onclick='copyRow(this)' />";
			jQuery("#history_table").jqGrid('setRowData', ids[i],
			{
				copy : copyInput
			});
		}
	}
	});
}

function copyRow(that){
	var rowid = $(that).parents("tr").index();
	var row = JSON.parse($("#history_table").jqGrid("getRowData", rowid).data_info);
	var bda01 = row.bda01;
	if(bda01 =='L'){
		typeClick("Jianyan");
		addJianyanCyxm(row);
	}
	else if(bda01 =='E'){
		typeClick("Jiancha");
		addJianchaCyxm(row)
	}
	else if(bda01 =='1' || bda01=="2"){
		typeClick("Xiyao");
		addXiyaoCyxm(row);
	}
	else if(bda01 =='8'){
		typeClick("Zhongyao");
		adviceZhongyao(row);
	}
	else if(bda01 =='S'){
		typeClick("Shoushu");
		addShoushuCyxm(row);
	}
	else if(("1238SE".indexOf(bda01) < 0 && row.vaf01a == 0 && row.vaf32 == 0)){
		 typeClick("Zhiliao");
		 addZhiliaoCyxm(row);
	}
	
}
function adviceZhongyao(dataObj){
	var zyjiangfa;
	var editzhongyaoobj ={};
	var bda01 = dataObj.bda01;
	var arr =[];
	if (bda01 == "3" || bda01 == "8")
	{
		var url = rootUrl + "/doctoradviceeditor/getVaf1Byvaf01a";
		var params ={};
		params.vaf01 = dataObj.vaf01;
		$.get(url, params, function(data)
		{
			debugger;
			var list = data.list;
			for (var i = 0; i < list.length; i++)
			{
				if (list[i].bda01 == 'T')
				{
					zyjiangfa = list[i].vaf22;
				}
				else if (list[i].bda01 == '3')
				{
					arr.push(list[i]);
				}

			}
			dataObj = $.extend(dataObj,
			{
				'zyjiangfa' : zyjiangfa
			});
			editzhongyaoobj['data'] = dataObj;
			for (var i = 0; i < arr.length; i++)
			{
				editzhongyaoobj['list'] = arr[i];
				addZhongyaoCyxm(editzhongyaoobj);
			}
		});
	}
}
function copyMutAdvice(){
	var selectedIds = $("#history_table").jqGrid("getGridParam", "selarrrow");
	if(selectedIds.length>0){
			for (var i = 0;i<selectedIds.length;i++){
				var row = JSON.parse($("#history_table").jqGrid("getRowData", selectedIds[i]).data_info);
				var bda01 = row.bda01;
				if(bda01 =='L'){
					typeClick("Jianyan");
					addJianyanCyxm(row);
				}
				else if(bda01 =='E'){
					typeClick("Jiancha");
					addJianchaCyxm(row)
				}
				else if(bda01 =='1' || bda01=="2"){
					typeClick("Xiyao");
					addXiyaoCyxm(row);
				}
				else if(bda01 =='8'){
					typeClick("Zhongyao");
					adviceZhongyao(row);
				}
				else if(bda01 =='S'){
					typeClick("Shoushu");
					addShoushuCyxm(row);
				}
				else if(("1238SE".indexOf(bda01) < 0 && row.vaf01a == 0 && row.vaf32 == 0)){
					 typeClick("Zhiliao");
					 addZhiliaoCyxm(row);
				}
			}
		
	}else {
		layer.msg("请选择要复制的医嘱",{time:2000,icon:0,skin: 'layui-layer-msg0'});
	}
}























